#include <stdio.h>
#include <stdlib.h>

#include <math.h>

#include "pub_lib.h"

#ifndef PI
    #define PI 3.14159265358979323846
#endif

/*
 * 给定一个点 P =(2,1),
 * 将该点绕原点先逆时针旋转 45◦，再平移 (1,2),
 * 计算出变换后点的坐标(要求用齐次坐标进行计算)。
 * rotate 45
 *	[cos45, -sin45, 0
 *	sin45, cos45, 0
 *	0, 0, 1]
 *
 *	translation [1,2]
 *	[1 0 1
 *	 0 1 2
 *	 0 0 1]
 * */

void homework0(void)
{
	Vector3 point = {2.0, 1.0, 1.0};
	Vector3 mid, result;
	Matrix rot = {
		cos(PI/4), -sin(PI/4), 0, 0,
		sin(PI/4), cos(PI/4), 0, 0,
		0, 0, 1, 0,
		0, 0, 0, 1
	};
	Matrix trans = {
		1, 0, 1, 0,
		0, 1, 2, 0,
		0, 0, 1, 0,
		0, 0, 0, 1
	};
	Matrix out;

	printf("homework0 start\n");
	//rotate first, then translation
	print_vector("original point", point);
	print_matrix3("rotate matrix", rot);
	print_matrix3("translation matrix", trans);

	mid = Vector3Transform(point, rot);
	print_vector("after rotate", mid);
	result = Vector3Transform(mid, trans);
	print_vector("then translation", result);

	//trans * rotate, then product vector
	out = matrxiMul(trans, rot);
	print_matrix3("trans * rotate", out);

	result = Vector3Transform(point, out);
	print_vector("final result", result);

	printf("homework0 end\n\n");
}

int main(int argc, char** argv)
{
	homework0();
    return 0;
}

